﻿using System;
using NetCore;
using NetCore.ORM.EF;
using NetCore.Code.BLL;
using NetCore.Log;
using log4net.Config;
using log4net;
using System.IO;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            ///log4日志记录
            var logRepository = LogManager.CreateRepository("NETCORERepository");

            XmlConfigurator.Configure(logRepository, new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "/log4net.config"));
            LogHelper.Init(logRepository);
            ApplicationEnvironments.Site = ConfigHelper.GetAppSettings<SiteConfig>("SiteConfig");
            ApplicationEnvironments.DefaultSession = new ApplicationSession();
            ApplicationEnvironments.ProviderType = (ProviderType)Enum.Parse(typeof(ProviderType), ApplicationEnvironments.Site.ProviderType);
            EFRepository eFRepository = new EFRepository();


          
            InitDataService initDataService = new InitDataService();
            initDataService.Init();

            //  string outcontent = "";
            ////  string outfile1 = null;
            //  NetCore.Code.BLL.DbCodeService dbCodeService = new DbCodeService();
            //  Dictionary<string, string> dicCode = new Dictionary<string, string>();
            //  var startDate = DateTime.Now;
            //  Console.WriteLine(startDate.ToString("yyyy-MM-dd HH:mm:ss"));
            //  //dbCodeService.CreateCodes("1,2,3,4", "201812261412481248154", ref outcontent, 0);
            //  string rootPath = ApplicationEnvironments.BaseDirectory+ApplicationEnvironments.TempPath+"code/";
            //  //if (dicCode != null && dicCode.Count > 0)
            //  //{
            //  //    foreach (var item in dicCode)
            //  //    {
            //  //        FileHelper.WriteLine(rootPath + item.Key,item.Value);
            //  //    }
            //  //}
            //  if (File.Exists(ApplicationEnvironments.BaseDirectory + ApplicationEnvironments.TempPath + "code.zip"))
            //  {
            //      File.Delete(ApplicationEnvironments.BaseDirectory + ApplicationEnvironments.TempPath + "code.zip");
            //  }
            //  //System.IO.Compression.ZipFile.CreateFromDirectory(rootPath,
            //  //    ApplicationEnvironments.BaseDirectory + ApplicationEnvironments.TempPath + "code.zip", System.IO.Compression.CompressionLevel.Optimal, true);
            // Console.WriteLine(outcontent);
            //  var endDate = DateTime.Now;
            //  Console.WriteLine(endDate.ToString("yyyy-MM-dd HH:mm:ss"));
            //  TimeSpan ts1 = new TimeSpan(startDate.Ticks);
            //  TimeSpan ts2 = new TimeSpan(endDate.Ticks);
            //  TimeSpan ts3 = ts1.Subtract(ts2).Duration();
            //  Console.WriteLine(ts3.Seconds);

            //ProcessInstanceService processInstance = new ProcessInstanceService();
            //processInstance.GetFlow("WF009", 0, true);
            //string strError = "";
            //string instanceId = "";
            // FlowParameterCollection valuePairs = new FlowParameterCollection();
            //      valuePairs.Add("submit", "1");
            //processInstance.Start("WF009", 0, "111111111111112", "测试流程", ApplicationEnvironments.DefaultSession.UserId, valuePairs, ref instanceId, ref strError);

            //valuePairs["Submit"] = "1";
            // valuePairs.Add("Submit", "1");
            //  processInstance.Run("20181215151352135208302532142",
            //     valuePairs, LinkTypeEnum.Submit, ApplicationEnvironments.DefaultSession.UserId, "fsafdasf", ref strError);

            Console.ReadKey();
        }


        public class ApplicationSession : IApplicationSession
        {
            public string UserId => "10000000000000004";

            public string UserName => throw new NotImplementedException();

            public string IPAddress => throw new NotImplementedException();

            public string FormAddress => throw new NotImplementedException();

            public string ServerAddress => throw new NotImplementedException();

            public string UserToken => throw new NotImplementedException();

            public HttpRequestLogModel GetContextModel()
            {
                throw new NotImplementedException();
            }

            public T GetUser<T>() where T : class, new()
            {
                throw new NotImplementedException();
            }

            public void SendMessage(string userno, int messageType, string message)
            {
                throw new NotImplementedException();
            }

            public void SetToken(string value)
            {
                throw new NotImplementedException();
            }
        }
    }
}
